package com.lianrui.app.member.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianrui.app.member.domain.MemberAddress;
import com.lianrui.app.member.service.IMemberAddressService;
import com.lianrui.app.member.vos.MemberAddressPage;
import com.lianrui.commons.ResultView;
import com.lianrui.core.AbstractController;
import com.lianrui.core.IService;

@Controller
@RequestMapping("/memberAddress")
public class MemberAddressController extends AbstractController<MemberAddressPage, MemberAddress, Integer>{

	private static final Logger LOGGER = LoggerFactory.getLogger(MemberAddressController.class);
	
	@Autowired
	IMemberAddressService memberAddressService;
	
	@Override
	public ResultView<Void> update(MemberAddress d) {
		return super.update(d);
	}
	
	/**
	 * 查找默认联系人信息
	 * @return
	 */
	@RequestMapping(value = "/findDefAddr")
	@ResponseBody
	public ResultView<MemberAddress> findDefAddr(Integer member_id) {
		
		ResultView<MemberAddress> view = new ResultView<MemberAddress>();
		MemberAddress memberAddress = memberAddressService.findDefAddr(member_id);
		view.setResult(memberAddress);
		
		return view;
	}
	
	/**
	 * 设置默认联系人信息
	 * @return
	 */
	@RequestMapping(value = "/updateToDefault")
	@ResponseBody
	public ResultView<MemberAddress> updateToDefault(Integer member_id,Integer addr_id) {
		
		ResultView<MemberAddress> view = new ResultView<MemberAddress>();
		
		memberAddressService.updateToDefault(member_id, addr_id);
		return view;
	}

	@Override
	public IService<MemberAddressPage, MemberAddress, Integer> getService() {
		return memberAddressService;
	}

	@Override
	public Logger getLogger() {
		return LOGGER;
	}

}
